<template>
  <div class="dashboard-editor-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.room"
        placeholder="房间名"
        style="width: 200px"
        class="filter-item"
      />
      <el-input
        v-model="listQuery.username"
        placeholder="用户名"
        style="width: 200px"
        class="filter-item"
      />
      <el-input
        v-model="listQuery.module"
        placeholder="P模块号"
        style="width: 200px"
        class="filter-item"
      />
      <el-button
        v-waves
        class="filter-item"
        :type="status?'warning':'primary'"
        icon="el-icon-search"
        @click="status?stopQuery():startQuery()"
      >
        {{ status | statusFilter }}
      </el-button>
    </div>

    <el-row :gutter="8">
      <el-row :gutter="8">
        <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 24}" :xl="{span: 24}" style="padding-right:8px;margin-bottom:30px;">
          <media-info ref="mediainfo" />
        </el-col>
      </el-row>
    </el-row>

  </div>
</template>

<script>

import waves from '@/directive/waves'
import MediaInfo from './components/MediaInfo.vue'

export default {
  directives: { waves },
  components: {
    MediaInfo
  },
  filters: {
    statusFilter(status) {
      if (status) { return '停止' } else { return '开始' }
    }
  },
  data() {
    return {
      status: false,
      listQuery: {
        username: '',
        room: '',
        module: 0
      }
    }
  },
  mounted() {
    if (this.$route.params.username) { this.listQuery.username = this.$route.params.username }
    if (this.$route.params.room) { this.listQuery.room = this.$route.params.room }
    if (this.$route.params.module) { this.listQuery.module = this.$route.params.module }
    if (this.listQuery.room || this.listQuery.module) {
      this.startQuery()
    }
  },
  methods: {
    startQuery() {
      this.status = true
      this.$refs.mediainfo.getChanTree(this.listQuery.module, this.listQuery.room, this.listQuery.username)
    },
    stopQuery() {
      this.status = false
      this.$refs.mediainfo.clearTimer()
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  //background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
